package com.chris.tinyurl.biz.configuration;

import com.chris.tinyurl.biz.id.DefaultIdGenerator;
import com.chris.tinyurl.biz.id.IdGenerator;
import com.chris.tinyurl.biz.tinyurl.TinyUrlConverter;
import com.chris.tinyurl.biz.tinyurl.impl.DefaultTinyUriConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TinyUrlConfiguration {

    @Bean
    @ConditionalOnMissingBean(IdGenerator.class)
    public IdGenerator idGenerator() {
        return new DefaultIdGenerator();
    }

    @Bean
    @ConditionalOnMissingBean(TinyUrlConverter.class)
    public TinyUrlConverter tinyUrlConverter(@Autowired IdGenerator idGenerator) {
        return new DefaultTinyUriConverter(idGenerator);
    }
}
